
#include <nfc/nfc.h>

#define MAX_DEVICE_COUNT 1
#define MAX_TARGET_COUNT 1

#define RF_REGULATION_TEST  0x58

// TxMode
#define MIFARE_106          (0x00 | (0x00 << 4))    // Mifare, 106 kbps
#define MIFARE_212          (0x00 | (0x01 << 4))    // Mifare, 212 kbps
#define MIFARE_424          (0x00 | (0x02 << 4))    // Mifare, 424 kbps
#define MIFARE_848          (0x00 | (0x03 << 4))    // Mifare, 848 kbps

int main(void)
{
  nfc_connstring connstrings[MAX_DEVICE_COUNT];
  int res = 0;

  nfc_context *context;
  nfc_init(&context);

  size_t device_count = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
  if (!device_count)
    printf("No NFC device found");

  nfc_device *device;

  printf("open device: %s\n", connstrings[0]);
  device = nfc_open(context, connstrings[0]);
  if (device == NULL) {
    printf("nfc_open() failed\n");
    return 1;
  }

  const uint8_t abtCmd[] = {RF_REGULATION_TEST, MIFARE_424};
  uint8_t abtRx[1];
  int ret = 0;

  ret = pn53x_transceive(device, abtCmd, sizeof(abtCmd), abtRx, sizeof(abtRx), 1000);

  
  printf("Press ENTER to exit\n");
  getchar();

  nfc_close(device);
  nfc_exit(context);

  return 0;
}
